package com.asset.dispoal.business.appoint.service.command;

import com.asset.dispoal.business.appoint.dto.CanAppointCaseRequest;
import com.asset.dispoal.business.appoint.dto.CanAppointCaseResponse;
import com.asset.dispoal.business.bsCase.domain.db.mapper.BsCaseMapper;
import com.asset.dispoal.commom.page.PagingQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

@Component
@Slf4j
public class QueryPageCanAppointCaseCommand implements BaseCommand<CanAppointCaseRequest, Result<PageVO<CanAppointCaseResponse>>> {

    @Autowired
    BsCaseMapper bsCaseMapper;

    @Override
    public Result<PageVO<CanAppointCaseResponse>> execute(CanAppointCaseRequest request) {
        int count = bsCaseMapper.queryCountCanAppointCase(request);
        Page<CanAppointCaseRequest> page = PagingQuery.getPage(count, request);
        PageVO<CanAppointCaseResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(count);
        if (page != null) {
            List<CanAppointCaseResponse> bsCases = bsCaseMapper.queryPageCanAppointCase(page);
            pageVO.setResult(bsCases);
        }
        return Result.ok(pageVO);
    }
}
